﻿namespace QLPhongKham.Access.Duoc
{
    using ConfigDatabase.Class;
    using Npgsql;
    using QLPhongKham.BaseClass.Chung;
    using System;

    public class DThongSo
    {
        private ConnectDatabase _condata;
        private NpgsqlConnection _conn;
        private dtoDSThongSo _dtots;
        private int _idthongso;

        public DThongSo()
        {
            this._idthongso = 13;
            this._condata = new ConnectDatabase();
            this._dtots = new dtoDSThongSo(this._condata);
        }

        public DThongSo(ConnectDatabase condata)
        {
            this._idthongso = 13;
            this._condata = condata;
            this._dtots = new dtoDSThongSo(this._condata);
        }

        private string f_GetThongSo(int stt)
        {
            this._dtots.ID = this._idthongso;
            this._dtots.STT = stt;
            this._dtots.TEN = "";
            this._dtots.GIATRI2 = "";
            this._dtots.GIATRI1 = "";
            this._dtots.Load();
            try
            {
                return this._dtots.GIATRI1;
            }
            catch
            {
                return "";
            }
        }

        private void f_SetThongSo(int stt, string ten, string giatri1)
        {
            this._dtots.ID = this._idthongso;
            this._dtots.STT = stt;
            this._dtots.TEN = ten;
            this._dtots.GIATRI1 = giatri1;
            this._dtots.GIATRI2 = "";
            if (!this._dtots.Update())
            {
                this._dtots.Insert();
            }
        }

        public int pApGia_PTGiaDichVu
        {
            get
            {
                try
                {
                    return int.Parse(this.f_GetThongSo(enSTT.ptgiadichvu.GetHashCode()));
                }
                catch
                {
                    return 0;
                }
            }
            set
            {
                this.f_SetThongSo(enSTT.ptgiadichvu.GetHashCode(), enSTT.ptgiadichvu.ToString(), value.ToString());
            }
        }

        public int pApGia_PTGiaThuong
        {
            get
            {
                try
                {
                    return int.Parse(this.f_GetThongSo(enSTT.ptgiathuong.GetHashCode()));
                }
                catch
                {
                    return 0;
                }
            }
            set
            {
                this.f_SetThongSo(enSTT.ptgiathuong.GetHashCode(), enSTT.ptgiathuong.ToString(), value.ToString());
            }
        }

        public bool pApGia_TheoGiaNhap
        {
            get
            {
                try
                {
                    return (this.f_GetThongSo(enSTT.apgiatheogianhap.GetHashCode()) != "0");
                }
                catch
                {
                    return false;
                }
            }
            set
            {
                this.f_SetThongSo(enSTT.apgiatheogianhap.GetHashCode(), enSTT.apgiatheogianhap.ToString(), value ? "1" : "0");
            }
        }

        public bool pApGia_TheoGiaNhapMax
        {
            get
            {
                try
                {
                    return (this.f_GetThongSo(enSTT.apgiatheogianhapmax.GetHashCode()) != "0");
                }
                catch
                {
                    return false;
                }
            }
            set
            {
                this.f_SetThongSo(enSTT.apgiatheogianhapmax.GetHashCode(), enSTT.apgiatheogianhapmax.ToString(), value ? "1" : "0");
            }
        }

        public bool pXuat_CanhBaoHetDate
        {
            get
            {
                try
                {
                    return (this.f_GetThongSo(enSTT.xcanhbaohetdate.GetHashCode()) != "0");
                }
                catch
                {
                    return false;
                }
            }
            set
            {
                this.f_SetThongSo(enSTT.xcanhbaohetdate.GetHashCode(), "xuatkho_canhbaohetdate", value ? "1" : "0");
            }
        }

        public int pXuat_CanhBaoHetDate_SoNgay
        {
            get
            {
                try
                {
                    return int.Parse(this.f_GetThongSo(enSTT.xcanhbaohetdate_songay.GetHashCode()));
                }
                catch
                {
                    return 0;
                }
            }
            set
            {
                this.f_SetThongSo(enSTT.xcanhbaohetdate_songay.GetHashCode(), "xuatkho_canhbaosongayhetdate", value.ToString());
            }
        }

        public bool pXuat_NhapTruocXuatTruoc
        {
            get
            {
                try
                {
                    return (this.f_GetThongSo(enSTT.xfifo.GetHashCode()) != "0");
                }
                catch
                {
                    return false;
                }
            }
            set
            {
                this.f_SetThongSo(enSTT.xfifo.GetHashCode(), "xuatkho_nhaptruocxuattruoc", value ? "1" : "0");
            }
        }

        public bool pXuat_XuatTheoDate
        {
            get
            {
                try
                {
                    return (this.f_GetThongSo(enSTT.xtheodate.GetHashCode()) != "0");
                }
                catch
                {
                    return false;
                }
            }
            set
            {
                this.f_SetThongSo(enSTT.xtheodate.GetHashCode(), "xuatkho_theodate", value ? "1" : "0");
            }
        }

        private enum enSTT
        {
            apgiatheogianhap = 3,
            apgiatheogianhapmax = 4,
            ptgiadichvu = 2,
            ptgiathuong = 1,
            xcanhbaohetdate = 7,
            xcanhbaohetdate_songay = 8,
            xfifo = 5,
            xtheodate = 6
        }
    }
}

